use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// 企业微信消息结构
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct WeChatMessage {
    pub msgid: String,
    pub aibotid: String,
    pub chattype: String,
    pub from: WeChatMessageFrom,
    pub msgtype: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<WeChatMessageText>,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct WeChatMessageFrom {
    pub userid: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct WeChatMessageText {
    pub content: String,
}

/// 企业微信加密请求 (POST body)
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct WeChatEncryptedRequest {
    pub encrypt: String,  // POST body 只包含 encrypt 字段
}

/// 企业微信加密响应
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct WeChatEncryptedResponse {
    pub encrypt: String,
    pub msg_signature: String,
    pub timestamp: String,
    pub nonce: String,
}

/// 企业微信响应消息
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct WeChatResponse {
    pub msgtype: String,
    pub text: WeChatResponseText,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct WeChatResponseText {
    pub content: String,
}

impl WeChatResponse {
    pub fn new_text(content: String) -> Self {
        Self {
            msgtype: "text".to_string(),
            text: WeChatResponseText { content },
        }
    }
}
